﻿using BaseFunction.DEncrypt;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using YY.BLL;

namespace BaseFunction.StaticTableClass
{
   public class agent_users_Help
    {
       public  static  YY.BLL.agent_users bll_agent_users=new agent_users();
       /// <summary>
       /// 根据用户名密码返回一个实体
       /// </summary>
       public YY.Model.agent_users GetModel(string user_name, string password, bool is_encrypt)
       {
           string salt = "";
           //检查一下是否需要加密
           if (is_encrypt)
           {
               //先取得该用户的随机密钥
               DataTable dt = MsSql2008.Query(string.Format("SELECT TOP 1 salt FROM tb_agent_users WHERE user_name='{0}'", user_name)).Tables[0];
               if (dt.Rows.Count > 0)
               {
                   salt = dt.Rows[0]["salt"].ToString();
               }

               if (string.IsNullOrEmpty(salt))
               {
                   return null;
               }
               //把明文进行加密重新赋值
               password = DESEncrypt.Encrypt(password, salt);
           }
           return GetModel(user_name, password);
       }
       /// <summary>
       /// 根据用户名密码返回一个实体
       /// </summary>
       public YY.Model.agent_users GetModel(string user_name, string password)
       {
           string sql = string.Format("SELECT id FROM tb_agent_users WHERE user_name='{0}' and password='{1}' and is_lock=0", user_name, password);
           object obj = MsSql2008.GetSingle(sql);
           if (obj != null)
           {
               return bll_agent_users.GetModel(Convert.ToInt32(obj));
           }
           return null;
       }
       public static bool ExecuteSql(string strSql)
       {
           return BaseFunction.MsSql2008.ExecuteSql(strSql) > 0 ? true : false;
       }
    }
}
